package encheres.ihm;

import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.border.TitledBorder;

public class ListeClients extends JPanel
{
	private JPanel main;
	
	private HashMap<String, JPanel> clients;
	
	public ListeClients()
	{
		setLayout(new BorderLayout());
		setBorder(new TitledBorder(null, "Liste des clients", TitledBorder.LEADING, TitledBorder.TOP, null, null));

		main = new JPanel();
		main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
		add(main, BorderLayout.NORTH);
		
		clients = new HashMap<String, JPanel>();
	}

	public void addClient(String nom, ActionListener ecouteurBoutonExclure, ActionListener ecouteurBoutonReinclure)
	{
		final JPanel pan = new JPanel(new FlowLayout(FlowLayout.LEFT));
			pan.setBackground(Color.orange);
			JLabel lab = new JLabel(nom);
			lab.setBackground(Color.red);
			
			/******************************* EXCLURE ************************/
			final JButton butExclure = new JButton("Exclure");
			butExclure.setBorder(BorderFactory.createLineBorder(Color.black));
			butExclure.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			butExclure.setPreferredSize(new Dimension(100,30));			
			butExclure.addActionListener(ecouteurBoutonExclure);
			/****************************************************************/

			
			/******************************* REINCLURE ************************/
			final JButton butReinclure = new JButton("Reinclure");
			butReinclure.setBorder(BorderFactory.createLineBorder(Color.black));
			butReinclure.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
			butReinclure.setPreferredSize(new Dimension(100,30));		
			butReinclure.setEnabled(false);
			butReinclure.addActionListener(ecouteurBoutonReinclure);
			/****************************************************************/

			/*************************** ACTIONLISTENER *********************/				
			butReinclure.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e) {
					pan.setBackground(Color.orange);
					butReinclure.setEnabled(false);
					butExclure.setEnabled(true);
				}
			});
			
			butExclure.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e) {
					pan.setBackground(Color.red);
					butExclure.setEnabled(false);
					butReinclure.setEnabled(true);
				}
			});
			/****************************************************************/
				
			pan.add(lab);
			pan.add(butExclure);
			pan.add(butReinclure);
		main.add(pan);
		
		clients.put(nom, pan);
	}

}
